/* eslint-disable no-unused-vars */
import bj from './bj.jpeg';
let data = [
    '王绾柚',
    '王洛苡',
    '王梨珂',
    '王梓沐',
    '王清一',
    '杨朝来',
    '蒋平',
    '唐灿华',
    '马达',
    '赵小雪',
    '薛文泉',
    '丁建',
    '凡小芬',
    '文彭凤',
    '王丽',
    '王建华',
];
let btn = document.querySelector('button');
let text = document.querySelector('.text');
let all = document.querySelector('.all');
let p = document.querySelector('p');
let click = 0;
let timer;
let i;
all.style['background-image'] = 'url(' + bj + ')'; //设置背景图片
btn.addEventListener('click', () => {
    if (data.length == 0) {
        text.innerText = '抽取完毕';
        btn.setAttribute('disabled', 'true');
        btn.style.backgroundColor = 'grey';
    }
    if (click % 2 == 0 && data.length > 0) {
        setTimeout(() => click++);
        timer = setInterval(() => {
            i = Math.floor(Math.random() * data.length);
            text.innerText = data[i];
            btn.innerText = '停止抽取';
        }, 100);
    }
    if (click % 2 == 1) {
        clearInterval(timer);
        p.innerText += data[i] + '、';
        data.splice(i, 1);
        setTimeout(() => click++);
        btn.innerText = '开始抽取';
    }
});
